import java.util.ArrayList;
import java.util.List;

public class Solution {

    public List<List<Integer>> generate(int numRows){
        List<List<Integer>> ret = new ArrayList<>();
        //先处理第一行；
        List<Integer> list = new ArrayList<>();
         list.add(1);

        for (int i = 1; i < numRows; i++) {
            //开头
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            //中间
            List<Integer> preRow = ret.get(i);
            for (int j = 1; j < i ; j++) {
                //[i][j] = [i-1][j]+[i-1][j-1]
                int val = preRow.get(j) + preRow.get(j-1);
                curRow.add(val);
            }

            //末尾
            curRow.add(1);
            ret.add(curRow);


        }
        return ret;
    }
}